package com.qk.management.controller;

import com.qk.common.PageResult;
import com.qk.common.Result;
import com.qk.common.constant.BusinessStatusConstants;
import com.qk.dpmain.businesses.BusinessDo;
import com.qk.dto.business.BusinessDto;
import com.qk.dto.business.BusinessListDto;
import com.qk.dto.business.UpdateBusinessDto;
import com.qk.dto.HighSeas.HighSeasDto;
import com.qk.entity.Business;
import com.qk.management.service.BusinessSercivce;
import com.qk.vo.business.BusinessesVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

/**
 * @文件名: BusinessController
 * @作者: DX
 * @创建日期: 2025/10/15
 * @描述:
 */
@RestController
@RequestMapping("/businesses")
public class BusinessController {

    @Autowired
    private BusinessSercivce businessSercivce;

    @GetMapping("/pool")
    public Result highSeasList(HighSeasDto dto){
        PageResult<Business> pageResult = businessSercivce.highSeasList(dto);
        return Result.success(pageResult);
    }


    @PostMapping("/toCustomer/{id}")
    public Result toCustomer(@PathVariable Integer id)  {

        businessSercivce.toCustomer(id);

        return Result.success();
    }

    @PutMapping
    public Result updateBusinessById(@RequestBody UpdateBusinessDto dto) {
        businessSercivce.updateBusinessById(dto);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result getBusinessInfoById(@PathVariable Integer id){
        BusinessesVo businessVo = businessSercivce.getBusinessInfoById(id);
        return Result.success(businessVo);
    }


    @PutMapping("/back/{id}")
    public Result toHighSeas(@PathVariable Integer id){
        businessSercivce.updateById(BusinessDo.builder()
                .id(id)
                .status(BusinessStatusConstants.PSEUDO_CLUE)
                .updateTime(LocalDateTime.now())
                .build());
        return Result.success();
    }

    @PutMapping("/assign/{businessId}/{userId}")
    public Result toBusiness(@PathVariable Integer businessId ,@PathVariable Integer userId){
        businessSercivce.updateById(BusinessDo.builder()
                .id(businessId)
                .userId(userId)
                .updateTime(LocalDateTime.now())
                .status(BusinessStatusConstants.WAIT_FOLLOW_UP)
                .build()
        );
        return Result.success();
    }


    @GetMapping
    public Result list(BusinessListDto dto){

        PageResult<BusinessDo> pageResult = businessSercivce.businesslist(dto);

        return Result.success(pageResult);
    }

    @PostMapping
    public Result addBusiness(@RequestBody BusinessDto dto){

        businessSercivce.addBusiness(dto);

        return Result.success();
    }
}